<template>
	<view class="people">
		<view v-if="user.userid">
			<view><image class="people-avatar" :src="user.avatar"></image></view>
			<view>用户ID:{{ user.userid }}</view>
			<view>用户名:{{ user.name }}</view>
			<view>用户昵称:{{ user.nickname }}</view>
		</view>
		<view @click="gologin" v-else>登录</view>
	</view>
</template>

<script>
import { mapState, mapActions } from 'vuex';
import { isLogin } from '@/utils'
export default {
	data() {
		return {
			user: {}
		};
	},
	methods: {
		...mapActions(['userInfo']),
		gologin() {
			uni.reLaunch({
				url: '/pages/login/index'
			});
		},
		getUserInfo() {
			this.userInfo().then(res => {
				this.user = res;
			});
		}
	},
	mounted() {
		if (isLogin()) {
			this.getUserInfo();
		}
	}
};
</script>

<style lang="scss" scoped>
.people {
	&-avatar {
		width: 200rpx;
		height: 200rpx;
		border-radius: 50%;
	}
}
</style>
